package cn.fl.institution.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.service.ICstCorpBscInfoService;
import cn.fl.customer.service.ICstCorpTeamService;
import cn.fl.customer.service.ICstNpBscInfoService;
import cn.fl.customer.vo.*;
import cn.fl.enums.InsAccResEnum;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.institution.api.ISyflInsApiService;
import cn.fl.project.api.IPrjCstAccInfoApiService;
import cn.fl.project.condition.PrjCstAccInfoQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstAccInfoService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjCstAccInfoVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.SystemConstant;
import fl.customer.facade.customer.condition.CstCorpTeamQueryCondition;
import fl.customer.facade.customer.constant.CustomerConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @Description: 项目基础信息表 控制层 三一金融
 */
@Controller
@RequestMapping("/institution/syfl")
public class PrjBscInfoInsSyflController {

    @Autowired
    private IPrjBscInfoService prjBscInfoService; // 项目基础信息表

    @Autowired
    private IPrjCstAccInfoApiService prjCstAccInfoApiService; // 项目客户账户信息表

    @Autowired
    private ICstBscInfoService cstBscInfoService; // 客户基础信息

    @Autowired
    private ICstNpBscInfoService cstNpBscInfoService; // 自然人信息

    @Autowired
    private ICstCorpTeamService cstCorpTeamService;

    @Autowired
    private ICstCorpBscInfoService cstCorpBscInfoService;

    @Autowired
    private IPrjCstAccInfoService prjCstAccInfoService;//项目客户基础信息表

    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

    @Autowired
    private ISyflInsApiService syflInsApiService;


    @RequestMapping(value = "/saveSyflPrjAccInfo.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object saveSyflPrjAccInfo(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC, HttpServletRequest request) throws BaseException {
        BaseLogUtils.newWebLogger("三一金融保存更改客户信息:prjId:" + prjId + ",prjCstAccInfoQC:" + JSON.toJSONString(prjCstAccInfoQC)).info();
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.newWebLogger("三一金融新增修改客户账户信息,request:" +  JSON.toJSONString(request.getParameterMap())).info();
        String cstAccInfoId = request.getParameter("cstAccInfoId");//项目客户信息表id
        String insCode = request.getParameter("insCode");//机构code
//        String prjId = request.getParameter("prjId");//项目id
        String cstId = request.getParameter("cstId");//客户id
        String cstNm = request.getParameter("cstNm");//客户姓名
        String cstTypCd = request.getParameter("cstTypCd");

        String certNo = request.getParameter("certNo");

        String isSmallBus = request.getParameter("isSmallBus");
        String isSelfEmp = request.getParameter("isSelfEmp");

        String holdSituationCd = request.getParameter("holdSituationCd");
        String borrowerfeature = request.getParameter("borrowerfeature");
        String shtNm = request.getParameter("shtNm");

        String mp = request.getParameter("mp");//手机号
        String corpMp = request.getParameter("corpMp");

        String bkNo = request.getParameter("bkNo");
        String bkCd = request.getParameter("bkCd");//银行代码 -- 通用狮桥的数据字典表（CST0014） -- 资管特有的sys_cd_map_d表（M1041）
        String bkNm = request.getParameter("bkNm");//银行名称
        String accNo = request.getParameter("accNo");//银行账号
        String indCd = request.getParameter("indCd");
        String stdIndCd = request.getParameter("stdIndCd");
        String domicileProvince = request.getParameter("domicileProvince");//户籍所在地-省
        String domicleCity = request.getParameter("domicleCity");//户籍所在地-市
        String domicleCounty = request.getParameter("domicleCounty");//户籍所在地-县
        String idAddr = request.getParameter("idAddr");//详细地址
        String certValidSDt = request.getParameter("certValidSDt");//身份证有效起始时间
        String certValidEDt = request.getParameter("certValidEDt");//身份证有效结束时间

        DataResultVO dataResultVO = new DataResultVO();
        try {
            if (StringUtils.isEmpty(prjId)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "项目id为空!");
            }
            if (StringUtils.isEmpty(cstId)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "客户id为空!");
            }
            if (StringUtils.isBlank(cstNm)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "客户名称为空!");
            }
            if (StringUtils.isEmpty(cstTypCd)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "客户类型为空!");
            }

            if(StringUtils.isBlank(bkNo)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护联行号!");
            }
            if (CustomerConstant.CST_TYP_CD_NP.equals(cstTypCd)) {
                if (StringUtils.isEmpty(certNo)) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "身份证号为空");
                }
                if(StringUtils.isBlank(bkNm) || StringUtils.isBlank(bkCd)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护开户银行信息!");
                }
                if(StringUtils.isBlank(accNo)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护银行卡号!");
                }
                if(StringUtils.isBlank(mp)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护银行预留手机号!");
                }
                if(StringUtils.isBlank(isSmallBus)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护是否小微企业!");
                }
                if(StringUtils.isBlank(isSelfEmp)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护是否个体工商户!");
                }
            }
            if (CustomerConstant.CST_TYP_CD_CORP.equals(cstTypCd)) {
                if (StringUtils.isEmpty(certNo)) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护法人代表身份证号!");
                }
                if(StringUtils.isBlank(accNo)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护公司公户还款账号!");
                }
//                if(StringUtils.isBlank(shtNm)){
//                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "公司名称为空.");
//                }
                if(StringUtils.isBlank(borrowerfeature)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护借款人特征!");
                }
                if(StringUtils.isBlank(holdSituationCd)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护控股情况!");
                }
                if(StringUtils.isBlank(corpMp)){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护法人代表手机号!");
                }
            }
            if(StringUtils.isBlank(indCd)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护所属行业!");
            }
            if(StringUtils.isBlank(stdIndCd)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护资行业!");
            }
            if(StringUtils.isBlank(domicileProvince)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护所在-省!");
            }
            if(StringUtils.isBlank(domicleCity)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护所在地-市!");
            }
            if(StringUtils.isBlank(idAddr)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护所在地-详细地址!");
            }
            if(StringUtils.isBlank(certValidSDt)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护证件有效起始日期!");
            }
            if(StringUtils.isBlank(certValidEDt)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护证件有效终止日期!");
            }
            if (StringUtils.isNotBlank(certValidEDt)) {
                if((!DateUtils.isDate(certValidEDt, "yyyy-MM-dd"))
                        &&(!certValidEDt.equals(PropertiesCacheUtils.getProperty(SystemConstant.CHECK_DATE_LONG)))){
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请维护证件有效终止日期格式（yyyy-MM-dd 或 长期）！");
                }
            }

            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(Long.valueOf(prjId));
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SYFL);
            BaseLogUtils.newWebLogger("三一金融根据prjId获取账户信息Start===prjId:" + prjId ).info();
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            BaseLogUtils.newWebLogger("三一金融根据prjId获取账户信息Start===prjId:" + prjId + ",prjCstAccInfoVOS:" + JSON.toJSONString(prjCstAccInfoVOS)).info();
            PrjCstAccInfoQueryCondition condition = new PrjCstAccInfoQueryCondition();
            PrjCstAccInfoVO prjCstAccInfoVO = null;
            if (CollectionUtils.isNotEmpty(prjCstAccInfoVOS)) {
                prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
                //说明该项目已存在账户信息 则跟据id进行修改
                condition.setId(prjCstAccInfoVO.getId());
                condition.setAccResCd(prjCstAccInfoVO.getAccResCd());
                condition.setChkRstCd(prjCstAccInfoVO.getChkRstCd());
            }
            if (null != prjCstAccInfoVO && InsAccResEnum.SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd())
                                        && (InsAccResEnum.FST_BIND_SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd()) || InsAccResEnum.SEC_BIND_SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd()))) {
                // 已绑卡
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "已绑卡,不可修改客户信息.");
            }

            BaseLogUtils.newWebLogger("三一金融查询项目基础信息Start===prjId:" + prjId).info();
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
            BaseLogUtils.newWebLogger("三一金融查询项目基础信息End===prjId:" + prjId + ",prjBscInfoVO:" + JSON.toJSONString(prjBscInfoVO)).info();
            if (null == prjBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "未查询到项目信息");
            }
            BaseLogUtils.newWebLogger("三一金融查询客户信息Start:cstId:" + cstId).info();
            CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectBy(Long.valueOf(cstId), prjBscInfoVO.getBuOrgCd());
            BaseLogUtils.newWebLogger("三一金融查询客户信息End:cstId:" + cstId + ",cstBscInfoVO:" + JSON.toJSONString(cstBscInfoVO)).info();
            CstExtInfoVO cstExtInfoVO = cstBscInfoVO.getCstExtInfoVO();
            if (StringUtils.isNotEmpty(cstExtInfoVO.getNum9())) {
                Long num9 = DecimalUtils.convertYuanToFen(Double.valueOf(cstExtInfoVO.getNum9()));
                cstExtInfoVO.setNum9(String.valueOf(num9));
            }

            if (null != cstBscInfoVO) {
                if (!Objects.equals(cstBscInfoVO.getIndCd(), indCd)) {
                    cstBscInfoVO.setIndCd(indCd);
                    BaseLogUtils.newWebLogger("saveSyflPrjAccInfo.三一金融修改客户基础信息End===Start:" + cstId).info();
                    boolean modify = this.cstBscInfoService.modify(cstBscInfoVO);
                    BaseLogUtils.newWebLogger("saveSyflPrjAccInfo.三一金融修改客户基础信息End===cstId:" + cstId + ",modify:" + modify).info();
                }
            }

            switch (cstTypCd) {
                case CustomerConstant.CST_TYP_CD_NP:
                    // 自然人
                    CstNpBscInfoVO cstNpBscInfoVO = cstBscInfoVO.getCstNpBscInfoVO();
//                    CstNpBscInfoVO cstNpBscInfoVO = this.cstNpBscInfoService.selectById(Long.valueOf(cstId));
                    BaseLogUtils.newWebLogger("三一金融查询自然人信息End===cstId:" + cstId + ",cstNpBscInfoVO:" + JSON.toJSONString(cstNpBscInfoVO)).info();
                    if(null != cstNpBscInfoVO) {
                        boolean npFlag = false;
                        if (!Objects.equals(cstNpBscInfoVO.getDomicileProvince(), domicileProvince)) {
                            npFlag = true;
                            cstNpBscInfoVO.setDomicileProvince(domicileProvince);
                        }
                        if (!Objects.equals(cstNpBscInfoVO.getDomicleCity(), domicleCity)) {
                            npFlag = true;
                            cstNpBscInfoVO.setDomicleCity(domicleCity);
                        }
                        if (!Objects.equals(cstNpBscInfoVO.getDomicleCounty(), domicleCounty)) {
                            npFlag = true;
                            cstNpBscInfoVO.setDomicleCounty(domicleCounty);
                        }
                        if (!Objects.equals(cstNpBscInfoVO.getIdAddr(), idAddr)) {
                            npFlag = true;
                            cstNpBscInfoVO.setIdAddr(idAddr);
                        }
                        if (!Objects.equals(cstNpBscInfoVO.getIsSmallBus(), isSmallBus)) {
                            npFlag = true;
                            cstNpBscInfoVO.setIsSmallBus(StringUtils.isEmpty(isSmallBus) ? cstNpBscInfoVO.getIsSmallBus() : Integer.valueOf(isSmallBus));
                        }
                        if (!Objects.equals(cstNpBscInfoVO.getIsSelfEmp(), isSelfEmp)) {
                            npFlag = true;
                            cstNpBscInfoVO.setIsSelfEmp(StringUtils.isEmpty(isSelfEmp) ? cstNpBscInfoVO.getIsSelfEmp() : Integer.valueOf(isSelfEmp));
                        }
                        if (!Objects.equals(cstNpBscInfoVO.getCertValidSDt(), certValidSDt)) {
                            npFlag = true;
                            cstNpBscInfoVO.setCertValidSDt(certValidSDt);
                        }
                        if (!Objects.equals(cstNpBscInfoVO.getCertValidEDt(), certValidEDt)) {
                            npFlag = true;
                            cstNpBscInfoVO.setCertValidEDt(certValidEDt);
                        }
                        if (!Objects.equals(cstNpBscInfoVO.getStdIndCd(), stdIndCd)) {
                            npFlag = true;
                            cstNpBscInfoVO.setStdIndCd(stdIndCd);
                        }
                        BaseLogUtils.newWebLogger("三一金融修改自然人信息===cstId:" + cstId + ",npFlag:" + npFlag).info();
                        if (npFlag) {
                            BaseLogUtils.newWebLogger("三一金融修改自然人信息Start===cstId:" + cstId + ",cstNpBscInfoVO:" + JSON.toJSONString(cstNpBscInfoVO)).info();
                            boolean modify = this.cstNpBscInfoService.modify(cstNpBscInfoVO);
                            BaseLogUtils.newWebLogger("三一金融修改自然人信息End===cstId:" + cstId + ",modify:" + modify).info();
                        }
                    }
                    break;
                case CustomerConstant.CST_TYP_CD_CORP:
                    // 法人
                    CstCorpBscInfoVO cstCorpBscInfoVo = cstBscInfoVO.getCstCorpBscInfoVO();
                    BaseLogUtils.newWebLogger("三一金融查询法人信息End===cstId:" + cstId + ",cstCorpBscInfoVo:" + JSON.toJSONString(cstCorpBscInfoVo)).info();
                    if (null != cstCorpBscInfoVo) {
                        boolean corpBscFlag = false;
                        if (!Objects.equals(cstCorpBscInfoVo.getBorrowerfeature(), borrowerfeature)) {
                            corpBscFlag = true;
                            cstCorpBscInfoVo.setBorrowerfeature(borrowerfeature);
                        }
                        if (!Objects.equals(cstCorpBscInfoVo.getHoldSituationCd(), holdSituationCd)) {
                            corpBscFlag = true;
                            cstCorpBscInfoVo.setHoldSituationCd(holdSituationCd);
                        }
                        if (!Objects.equals(cstCorpBscInfoVo.getStdIndCd(), stdIndCd)) {
                            corpBscFlag = true;
                            cstCorpBscInfoVo.setStdIndCd(stdIndCd);
                        }
                        BaseLogUtils.newWebLogger("三一金融修改法人基础信息===cstId:" + cstId + ",corpBscFlag:" + corpBscFlag).info();
                        if (corpBscFlag) {
                            BaseLogUtils.newWebLogger("三一金融修改法人基础信息Start===cstId:" + cstId + ",cstCorpBscInfoVo:" + JSON.toJSONString(cstCorpBscInfoVo)).info();
                            cstBscInfoVO.setCstCorpBscInfoVO(cstCorpBscInfoVo);
                            BaseLogUtils.newWebLogger("三一金融修改法人基础信息Start===cstId:" + cstId + ",cstBscInfoVO:" + JSON.toJSONString(cstBscInfoVO)).info();
                            boolean modify = this.cstBscInfoService.modify(cstBscInfoVO);
                            BaseLogUtils.newWebLogger("三一金融修改法人基础信息End===cstId:" + cstId + ",modify:" + modify).info();
                        }
                        CstCorpTeamQueryCondition cstCorpTeamQC = new CstCorpTeamQueryCondition();
                        cstCorpTeamQC.setCstId(Long.valueOf(cstId));
                        cstCorpTeamQC.setIsDel(BaseConstant.IS_YESNO_NO);
                        cstCorpTeamQC.setmTypCd(CustomerConstant.CST_CORP_TEAM_LOWER);
                        cstCorpTeamQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
                        BaseLogUtils.newWebLogger("三一金融查询法人客户信息Start:cstCorpTeamQC:" + JSON.toJSONString(cstCorpTeamQC)).info();
                        List<CstCorpTeamVO> cstCorpTeamVOS = this.cstCorpTeamService.searchList(cstCorpTeamQC);
                        BaseLogUtils.newWebLogger("三一金融查询法人客户信息End:cstCorpTeamVOS:" + JSON.toJSONString(cstCorpTeamVOS)).info();
                        CstCorpTeamVO cstCorpTeamVO = null;
                        for (CstCorpTeamVO vo : cstCorpTeamVOS) {
                            if (StringUtils.isNotBlank(vo.getCertTypCd()) && CustomerConstant.CERT_TYP_CD_0.equals(vo.getCertTypCd())) {
                                cstCorpTeamVO = vo;
                            }
                        }
                        if (null != cstCorpTeamVO) {
                            boolean corpTeamFlag = false;
                            if (!Objects.equals(cstCorpTeamVO.getPostProvince(), domicileProvince)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setPostProvince(domicileProvince);
                            }
                            if (!Objects.equals(cstCorpTeamVO.getPostCity(), domicleCity)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setPostCity(domicleCity);
                            }
                            if (!Objects.equals(cstCorpTeamVO.getPostCounty(), domicleCounty)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setPostCounty(domicleCounty);
                            }
                            if (!Objects.equals(cstCorpTeamVO.getHomeAddr(), idAddr)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setHomeAddr(idAddr);
                            }
                            if (!Objects.equals(cstCorpTeamVO.getCertValidSDt(), certValidSDt)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setCertValidSDt(certValidSDt);
                            }
                            if (!Objects.equals(cstCorpTeamVO.getCertValidEDt(), certValidEDt)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setCertValidEDt(certValidEDt);
                            }
                            if (!Objects.equals(cstCorpTeamVO.getCertNo(), certNo)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setCertNo(certNo);
                            }
                            if (!Objects.equals(cstCorpTeamVO.getmNm(), cstNm)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setMNm(cstNm);
                            }
                            if (!Objects.equals(cstCorpTeamVO.getMp1(), corpMp)) {
                                corpTeamFlag = true;
                                cstCorpTeamVO.setMp1(corpMp);
                            }
                            BaseLogUtils.newWebLogger("三一金融修改法人信息===cstId:" + cstId + ",corpTeamFlag:" + corpTeamFlag).info();
                            if (corpTeamFlag) {
                                cstCorpBscInfoVo.setCstCorpTeamVO(cstCorpTeamVO);
                                BaseLogUtils.newWebLogger("三一金融修改法人信息Start===cstId:" + cstId + ",cstCorpTeamVO:" + JSON.toJSONString(cstCorpTeamVO)).info();
                                boolean modify = this.cstCorpTeamService.modify(cstCorpTeamVO);
                                BaseLogUtils.newWebLogger("三一金融修改法人信息End===cstId:" + cstId + ",modify:" + modify).info();
                            }
                        }
                    }
                    break;
            }

            if (StringUtils.isNotEmpty(cstAccInfoId)) {
                condition.setId(Long.valueOf(cstAccInfoId));
            }
            condition.setPrjId(Long.valueOf(prjId));
            condition.setCstId(Long.valueOf(cstId));
            condition.setInsCode(insCode);
            condition.setCstNm(cstNm);
            condition.setAccNm(cstNm);
            condition.setBkNo(bkNo);
            condition.setBkCd(bkCd);
            condition.setBkNm(bkNm);
            condition.setAccNo(accNo);
            condition.setMp(mp);
            condition.setCertNo(certNo);
            condition.setCertTypCd(DictionaryConstant.CODE_CERT_TYP_CD_0);
            if (StringUtils.isEmpty(condition.getInsCode())) {
                condition.setInsCode(prjBscInfoVO.getInsCode());
            }
            BaseLogUtils.newWebLogger("新增或修改项目客户账户信息===prjId:" + prjId + ",condition:" + JSON.toJSONString(condition)).info();
            if (CustomerConstant.CST_TYP_CD_CORP.equals(cstTypCd)) {
                if (null == prjCstAccInfoVO) {
                    prjCstAccInfoVO = new PrjCstAccInfoVO();
                }
                prjCstAccInfoVO.setPrjId(condition.getPrjId());
                prjCstAccInfoVO.setCstId(cstBscInfoVO.getId());
                prjCstAccInfoVO.setInsCode(condition.getInsCode());
                prjCstAccInfoVO.setCstNm(cstBscInfoVO.getCstNm());
                prjCstAccInfoVO.setAccNm(cstBscInfoVO.getCstNm());
                prjCstAccInfoVO.setBkNo(condition.getBkNo());
                prjCstAccInfoVO.setBkCd(condition.getBkCd());
                prjCstAccInfoVO.setBkNm(condition.getBkNm());
                prjCstAccInfoVO.setAccNo(condition.getAccNo());
                prjCstAccInfoVO.setMp(corpMp);
                prjCstAccInfoVO.setCertNo(cstBscInfoVO.getCertNo());
                prjCstAccInfoVO.setCertTypCd(cstBscInfoVO.getCertTypCd());
                prjCstAccInfoVO.setChkRstCd("1");
                prjCstAccInfoVO.setAccResCd(InsAccResEnum.CST_APPLY_SUCCESS.code);
                prjCstAccInfoVO.setInsCode(condition.getInsCode());
                if (StringUtils.isEmpty(prjCstAccInfoVO.getId())) {
                    BaseLogUtils.newWebLogger("三一金融根据新增账户信息Start===prjId:" + prjId + ",prjCstAccInfoVO:" + JSON.toJSONString(prjCstAccInfoVO)).info();
                    Long add = this.prjCstAccInfoService.add(prjCstAccInfoVO);
                    BaseLogUtils.newWebLogger("三一金融根据新增账户信息End===prjId:" + prjId + ",add:" + add).info();
                    if (StringUtils.isEmpty(add)) {
                        dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "新增失败");
                    }
                } else {
                    BaseLogUtils.newWebLogger("三一金融根据修改账户信息Start===prjId:" + prjId + ",prjCstAccInfoVO:" + JSON.toJSONString(prjCstAccInfoVO)).info();
                    boolean modify = this.prjCstAccInfoService.modify(prjCstAccInfoVO);
                    BaseLogUtils.newWebLogger("三一金融根据修改账户信息End===prjId:" + prjId + ",modify:" + modify).info();
                    if (!modify) {
                        dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "修改失败");
                    }
                }
                Map<String,String> resultMap = new HashMap<>();
                resultMap.put("chkRstCd", "1");
                resultMap.put("rstDesc", "客户信息保存成功");
                resultMap.put("accResCd", prjCstAccInfoVO.getAccResCd());
                dataResultVO.setData(resultMap);
            } else {
                dataResultVO = this.prjCstAccInfoService.modifyPrjAccInfo(condition);
            }
            BaseLogUtils.newWebLogger("新增或修改项目客户账户信息===prjId:" + prjId + ",dataResultVO:" + JSON.toJSONString(dataResultVO)).info();
            if(BaseConstant.IS_YESNO_YES == dataResultVO.getSuccess()){
                Map<String,String> resultMap = (Map<String, String>) dataResultVO.getData();
                String chkRstCd = "";
                String rstDesc = "";
                chkRstCd = resultMap.get("chkRstCd");
                rstDesc = resultMap.get("rstDesc");
                if (chkRstCd.equals("1")) {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                    dataResultVO.setInfo("四要素信息校验通过");
                    if (CustomerConstant.CST_TYP_CD_CORP.equals(cstTypCd)) {
                        dataResultVO.setInfo("客户保存成功");
                    }

                } else {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo(rstDesc);
                }

                // 法人
//                if (CustomerConstant.CST_TYP_CD_CORP.equals(cstTypCd)) {
//                    // 避开二次四要素校验，直接更新
//                    if (StringUtils.isEmpty(condition.getId())) {
//                        condition.setId(1L);
//                    }
//                    condition.setCheckResult(chkRstCd);
//                    condition.setAccResCd("1");
//                    BaseLogUtils.newWebLogger("修改项目客户账户信息===prjId:" + prjId + ",condition:" + JSON.toJSONString(condition)).info();
//                    DataResultVO resultVO = this.prjCstAccInfoService.modifyPrjAccInfo(condition);
//                    BaseLogUtils.newWebLogger("修改项目客户账户信息===prjId:" + prjId + ",resultVO:" + JSON.toJSONString(resultVO)).info();
//                }
                // 自然人新增客户
                if (CustomerConstant.CST_TYP_CD_NP.equals(cstTypCd)) {
                    BaseLogUtils.newWebLogger("新增或修改自然人客户Start===prjId:" + prjId + ",condition:" + JSON.toJSONString(condition)).info();
                    DataResultDTO dataResultDTO = this.syflInsApiService.signAccount(String.valueOf(prjId));
                    BaseLogUtils.newWebLogger("新增或修改自然人客户End===prjId:" + prjId + ",dataResultDTO:" + JSON.toJSONString(dataResultDTO)).info();
                    if(dataResultDTO != null){
                        if(BaseConstant.IS_YESNO_YES_NM.equals(dataResultDTO.getCode())) {
                            dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                            dataResultVO.setInfo(dataResultDTO.getInfo());
                        } else {
                            // 开户失败
                            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                            dataResultVO.setInfo(dataResultDTO.getInfo());

                        }
                        if (null != dataResultDTO.getData()) {
                            JSONObject jsonObject = (JSONObject) dataResultDTO.getData();
                            jsonObject.put("chkRstCd", chkRstCd);
                            jsonObject.put("rstDesc", rstDesc);
                            dataResultVO.setData(jsonObject);
                        }
                    } else {
                        // 开户失败
                        dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                        dataResultVO.setInfo("开户失败，请联系客户核实银行名称、银行卡、预留手机号信息");
                    }
                }
            }
        } catch (BaseException ex) {
            BaseLogUtils.newWebLogger("新增或修改项目客户账户信息及校验失败===prjId:" + prjId + ",ex:" + ex.getMessage()).info();
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(ex.getMessage());
        } catch (Exception e){
            BaseLogUtils.newWebLogger("新增或修改项目客户账户信息及校验失败===prjId:" + prjId + ",e:" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "保存失败，系统异常");
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.newWebLogger("新增或修改项目客户账户信息及校验返回End===prjId:" + prjId + ",dataResultVO:" +  JSON.toJSONString(dataResultVO) + "-耗时:" + (endTm - startTm)).info();
        return dataResultVO;
    }

    @RequestMapping(value = "/sendVcodeSyfl.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object sendVcodeSyfl(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC, HttpServletRequest request) throws BaseException {
        BaseLogUtils.newWebLogger("三一金融获取验证码:prjId:" + prjId + ",prjCstAccInfoQC:" + JSON.toJSONString(prjCstAccInfoQC)).info();
        Long cstId = prjCstAccInfoQC.getCstId();//客户id
        if (StringUtils.isEmpty(cstId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "未获取到客户ID");
        }
        if (StringUtils.isEmpty(prjId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "未获取到项目ID");
        }

        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "调用成功");
        try {
            BaseLogUtils.newWebLogger("三一金融查询项目信息Start:prjId:" + prjId).info();
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjId);
            BaseLogUtils.newWebLogger("三一金融查询项目信息Start:prjId:" + prjId + ",prjBscInfoVO:" + prjBscInfoVO).info();
            if (null == prjBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融未查询到项目信息!");
            }
            BaseLogUtils.newWebLogger("三一金融查询客户信息Start:cstId:" + cstId).info();
            CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectBy(cstId, prjBscInfoVO.getBuOrgCd());
            BaseLogUtils.newWebLogger("三一金融查询客户信息End:cstId:" + cstId + ",cstBscInfoVO:" + JSON.toJSONString(cstBscInfoVO)).info();
            if (null == cstBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融未查询到客户信息!");
            }
            if (CustomerConstant.CST_TYP_CD_CORP.equals(cstBscInfoVO.getCstTypCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "法人客户无需获取验证码!");
            }
            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SYFL);
            BaseLogUtils.newWebLogger("三一金融获取账户信息,prjId:" + prjId).info();
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            BaseLogUtils.newWebLogger("三一金融获取账户信息,prjId:" + prjId  + ",prjCstAccInfoVOS:" + JSON.toJSONString(prjCstAccInfoVOS)).info();
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("请先保存项目客户信息");
                return dataResultVO;
            }
            // 四要素验证
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);
            if(null == prjCstAccInfoVO.getChkRstCd() || !"1".equals(prjCstAccInfoVO.getChkRstCd())) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("四要素信息有误,请修改");
                return dataResultVO;
            }
            if (null == prjCstAccInfoVO.getAccResCd() || InsAccResEnum.INIT_STATUS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("请先保存项目客户信息");
                return dataResultVO;
            } else if (InsAccResEnum.SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd()) || InsAccResEnum.FST_BIND_SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("已绑卡,无需再次获取");
                return dataResultVO;
            }
            // 发送短信
            DataResultDTO dto = this.syflInsApiService.getVerificationCodeSyfl(String.valueOf(prjId));
            if (null == dto) {
                dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "调用获取验证码接口返回空");
            } else {
                if (dto.getCode().equals(BaseConstant.IS_YESNO_YES_NM)) {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                }
                if (dto.getCode().equals(BaseConstant.IS_YESNO_NO_NE)) {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                }
                dataResultVO.setInfo(dto.getInfo());
                dataResultVO.setData(dto.getData());
            }
        } catch (Exception e) {
            BaseLogUtils.newWebLogger("三一金融调用获取验证码接口异常,prjId:" + prjId + ",e:" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "调用获取验证码接口异常,"+e);
        }
        BaseLogUtils.newWebLogger("三一金融获取验证码结果,prjId:" + prjId + ",dataResultVO:" + JSON.toJSONString(dataResultVO)).info();
        return dataResultVO;
    }

    @RequestMapping(value = "/syflBindCard.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object syflBindCard(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC, HttpServletRequest request) throws BaseException {
        BaseLogUtils.newWebLogger("三一金融绑卡:prjId:" + prjId + ",prjCstAccInfoQC:" + JSON.toJSONString(prjCstAccInfoQC)).info();
        Long startTm = System.currentTimeMillis();
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "通联绑卡成功");
        String vCode = prjCstAccInfoQC.getPhoneCode();
        if (StringUtils.isEmpty(prjId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "项目id为空!");
        }
        if (StringUtils.isBlank(vCode)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "请输入验证码!");
        }
        try {
            BaseLogUtils.newWebLogger("三一金融查询项目信息Start:prjId:" + prjId).info();
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjId);
            BaseLogUtils.newWebLogger("三一金融查询项目信息End:prjId:" + prjId + ",prjBscInfoVO:" + prjBscInfoVO).info();
            if (null == prjBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融未查询到项目信息!");
            }
            BaseLogUtils.newWebLogger("三一金融查询客户信息Start:cstId:" + prjBscInfoVO.getCstId()).info();
            CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectBy(prjBscInfoVO.getCstId(), prjBscInfoVO.getBuOrgCd());
            BaseLogUtils.newWebLogger("三一金融查询客户信息End:cstId:" + prjBscInfoVO.getCstId() + ",cstBscInfoDTO:" + JSON.toJSONString(cstBscInfoVO)).info();
            if (null == cstBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融未查询到客户信息!");
            }
            if (CustomerConstant.CST_TYP_CD_CORP.equals(cstBscInfoVO.getCstTypCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "法人客户无需绑卡!");
            }
            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SYFL);
            BaseLogUtils.newWebLogger("三一金融查询客户账户信息Start:prjId:" + prjId).info();
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            BaseLogUtils.newWebLogger("三一金融查询客户账户信息End:prjId:" + prjId + ",prjCstAccInfoVOS:" + JSON.toJSONString(prjCstAccInfoVOS)).info();
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请先保存项目客户信息");
            }
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);

            if(null == prjCstAccInfoVO.getChkRstCd() || !"1".equals(prjCstAccInfoVO.getChkRstCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "四要素信息有误,请修改");
            }
            if (null == prjCstAccInfoVO.getAccResCd() || InsAccResEnum.INIT_STATUS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请先保存项目客户信息");
            } else if (InsAccResEnum.SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd()) || InsAccResEnum.FST_BIND_SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "已绑卡,无需再次绑卡");
            }

            // 签约绑卡
            BaseLogUtils.newWebLogger("三一金融绑卡Start:prjId:" + prjId + ",vCode:" + vCode).info();
            DataResultDTO dataResultDTO = this.syflInsApiService.signTL(String.valueOf(prjId), vCode);
            BaseLogUtils.newWebLogger("三一金融绑卡End:prjId:" + prjId + ",vCode:" + vCode + ",dataResultDTO:" + JSON.toJSONString(dataResultDTO)).info();
            if(dataResultDTO!=null){
                if(BaseConstant.IS_YESNO_YES_NM.equals(dataResultDTO.getCode())) {//签约绑卡成功
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                    dataResultVO.setInfo(dataResultDTO.getInfo());
                }else{//签约绑卡失败
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo(dataResultDTO.getInfo());
                }
                dataResultVO.setData(dataResultDTO.getData());
            }else{//签约绑卡失败
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("很抱歉,您本次的绑卡操作失败,请重新操作绑卡");
            }
        } catch (BaseException ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("三一金融绑卡失败:prjId:" + prjId + ",vCode:" + vCode + ",ex:" + ex.getMessage()).info();
        } catch (Exception e){
            BaseLogUtils.newWebLogger("三一金融绑卡失败,系统异常:prjId:" + prjId + ",vCode:" + vCode + ",e:" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "通联签约绑卡失败,系统异常");
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.newWebLogger("三一金融绑卡返回:prjId:" + prjId + ",vCode:" + vCode + ",dataResultVO:" + JSON.toJSONString(dataResultVO) + "-耗时:" + (endTm - startTm)).info();
        return dataResultVO;
    }

    /**
     * 获取子行业列表
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/getSyflStdIndList.do", method = {RequestMethod.GET})
    @ResponseBody
    public DataResultVO getSyflStdIndList(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newWebLogger("查询子行业列表:request:" + JSON.toJSONString(request.getParameterMap())).info();
        String indCd = request.getParameter("indCd");
        if(StringUtils.isEmpty(indCd)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "所属行业值为空!");
        }
        BaseLogUtils.newWebLogger("查询子行业列表Start").info();
        List<SysDictionaryDTO> sysDictionaryDTOS = this.sysDictionaryApiService.searchChild(CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_GRP_CST_SID_IND_CD, indCd);
        BaseLogUtils.newWebLogger("查询子行业列表End:sysDictionaryDTOS:" + JSON.toJSONString(sysDictionaryDTOS)).info();
        if (CollectionUtils.isNotEmpty(sysDictionaryDTOS)) {
            List<KeyValueVO> list =  new ArrayList<>();
            for(SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOS) {
                KeyValueVO kv = new KeyValueVO();
                kv.setKey(sysDictionaryDTO.getCode());
                kv.setValue(sysDictionaryDTO.getCodeNm());
                list.add(kv);
            }
            return new DataResultVO(BaseConstant.IS_YESNO_YES, "查询成功", list);
        } else {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "未查到子行业列表");
        }
    }

    @RequestMapping(value = "/sendVcodeSyflForCorp.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object sendVcodeSyflForCorp(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC, HttpServletRequest request) throws BaseException {
        BaseLogUtils.newWebLogger("三一金融法人获取验证码:prjId:" + prjId + ",prjCstAccInfoQC:" + JSON.toJSONString(prjCstAccInfoQC)).info();
        Long cstId = prjCstAccInfoQC.getCstId();//客户id
        if (StringUtils.isEmpty(cstId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "未获取到客户ID");
        }
        if (StringUtils.isEmpty(prjId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "未获取到项目ID");
        }

        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "调用成功");
        try {
            BaseLogUtils.newWebLogger("三一金融法人查询项目信息Start:prjId:" + prjId).info();
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjId);
            BaseLogUtils.newWebLogger("三一金融法人查询项目信息Start:prjId:" + prjId + ",prjBscInfoVO:" + prjBscInfoVO).info();
            if (null == prjBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融未查询到项目信息!");
            }
            BaseLogUtils.newWebLogger("三一金融法人查询客户信息Start:cstId:" + cstId).info();
            CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectBy(cstId, prjBscInfoVO.getBuOrgCd());
            BaseLogUtils.newWebLogger("三一金融法人查询客户信息End:cstId:" + cstId + ",cstBscInfoVO:" + JSON.toJSONString(cstBscInfoVO)).info();
            if (null == cstBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融法人未查询到客户信息!");
            }

            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SYFL);
            BaseLogUtils.newWebLogger("三一金融法人获取账户信息,prjId:" + prjId).info();
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            BaseLogUtils.newWebLogger("三一金融法人获取账户信息,prjId:" + prjId  + ",prjCstAccInfoVOS:" + JSON.toJSONString(prjCstAccInfoVOS)).info();
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("请先保存项目客户信息");
                return dataResultVO;
            }
            // 四要素验证
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);

            if (null == prjCstAccInfoVO.getAccResCd() || InsAccResEnum.INIT_STATUS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("请先保存项目客户信息");
                return dataResultVO;
            } else if (InsAccResEnum.SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("已绑卡,无需再次获取");
                return dataResultVO;
            }
            // 发送短信
            DataResultDTO dto = this.syflInsApiService.getVerificationCodeForCorp(String.valueOf(prjId));
            if (null == dto) {
                dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "调用获取验证码接口返回空");
            } else {
                if (dto.getCode().equals(BaseConstant.IS_YESNO_YES_NM)) {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                }
                if (dto.getCode().equals(BaseConstant.IS_YESNO_NO_NE)) {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                }
                dataResultVO.setInfo(dto.getInfo());
                dataResultVO.setData(dto.getData());
            }
        } catch (Exception e) {
            BaseLogUtils.newWebLogger("三一金融法人调用获取验证码接口异常,prjId:" + prjId + ",e:" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "调用获取验证码接口异常,"+e);
        }
        BaseLogUtils.newWebLogger("三一金融法人获取验证码结果,prjId:" + prjId + ",dataResultVO:" + JSON.toJSONString(dataResultVO)).info();
        return dataResultVO;
    }

    @RequestMapping(value = "/syflBindCardForCorp.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object syflBindCardForCorp(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC, HttpServletRequest request) throws BaseException {
        BaseLogUtils.newWebLogger("三一金融法人绑卡:prjId:" + prjId + ",prjCstAccInfoQC:" + JSON.toJSONString(prjCstAccInfoQC)).info();
        Long startTm = System.currentTimeMillis();
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "法人绑卡成功");
        String vCode = prjCstAccInfoQC.getPhoneCode();
        if (StringUtils.isEmpty(prjId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "项目id为空!");
        }
        if (StringUtils.isBlank(vCode)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "请输入验证码!");
        }
        try {
            BaseLogUtils.newWebLogger("三一金融法人查询项目信息Start:prjId:" + prjId).info();
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjId);
            BaseLogUtils.newWebLogger("三一金融法人查询项目信息End:prjId:" + prjId + ",prjBscInfoVO:" + prjBscInfoVO).info();
            if (null == prjBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融未查询到项目信息!");
            }
            BaseLogUtils.newWebLogger("三一金融法人查询客户信息Start:cstId:" + prjBscInfoVO.getCstId()).info();
            CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectBy(prjBscInfoVO.getCstId(), prjBscInfoVO.getBuOrgCd());
            BaseLogUtils.newWebLogger("三一金融法人查询客户信息End:cstId:" + prjBscInfoVO.getCstId() + ",cstBscInfoDTO:" + JSON.toJSONString(cstBscInfoVO)).info();
            if (null == cstBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融法人未查询到客户信息!");
            }

            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SYFL);
            BaseLogUtils.newWebLogger("三一金融法人查询客户账户信息Start:prjId:" + prjId).info();
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            BaseLogUtils.newWebLogger("三一金融法人查询客户账户信息End:prjId:" + prjId + ",prjCstAccInfoVOS:" + JSON.toJSONString(prjCstAccInfoVOS)).info();
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请先保存项目客户信息");
            }
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);

            if (null == prjCstAccInfoVO.getAccResCd() || InsAccResEnum.INIT_STATUS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请先保存项目客户信息");
            } else if (InsAccResEnum.SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "已绑卡,无需再次绑卡");
            }

            // 签约绑卡
            BaseLogUtils.newWebLogger("三一金融法人绑卡Start:prjId:" + prjId + ",vCode:" + vCode).info();
            DataResultDTO dataResultDTO = this.syflInsApiService.signForCorp(String.valueOf(prjId), vCode);
            BaseLogUtils.newWebLogger("三一金融法人绑卡End:prjId:" + prjId + ",vCode:" + vCode + ",dataResultDTO:" + JSON.toJSONString(dataResultDTO)).info();
            if(dataResultDTO!=null){
                if(BaseConstant.IS_YESNO_YES_NM.equals(dataResultDTO.getCode())) {//签约绑卡成功
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                    dataResultVO.setInfo(dataResultDTO.getInfo());
                }else{//签约绑卡失败
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo(dataResultDTO.getInfo());
                }
                dataResultVO.setData(dataResultDTO.getData());
            }else{//签约绑卡失败
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("很抱歉,您本次的绑卡操作失败,请重新操作绑卡");
            }
        } catch (BaseException ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("三一金融法人绑卡失败:prjId:" + prjId + ",vCode:" + vCode + ",ex:" + ex.getMessage()).info();
        } catch (Exception e){
            BaseLogUtils.newWebLogger("三一金融法人绑卡失败,系统异常:prjId:" + prjId + ",vCode:" + vCode + ",e:" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "很抱歉,您本次的绑卡操作失败,请重新操作绑卡");
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.newWebLogger("三一金融法人绑卡返回:prjId:" + prjId + ",vCode:" + vCode + ",dataResultVO:" + JSON.toJSONString(dataResultVO) + "-耗时:" + (endTm - startTm)).info();
        return dataResultVO;
    }

    @RequestMapping(value = "/sendVcodeSyflForNp.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object sendVcodeSyflForNp(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC, HttpServletRequest request) throws BaseException {
        BaseLogUtils.newWebLogger("三一金融自然人获取验证码:prjId:" + prjId + ",prjCstAccInfoQC:" + JSON.toJSONString(prjCstAccInfoQC)).info();
        Long cstId = prjCstAccInfoQC.getCstId();//客户id
        if (StringUtils.isEmpty(cstId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "未获取到客户ID");
        }
        if (StringUtils.isEmpty(prjId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "未获取到项目ID");
        }

        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "调用成功");
        try {
            BaseLogUtils.newWebLogger("三一金融自然人查询项目信息Start:prjId:" + prjId).info();
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjId);
            BaseLogUtils.newWebLogger("三一金融自然人查询项目信息Start:prjId:" + prjId + ",prjBscInfoVO:" + prjBscInfoVO).info();
            if (null == prjBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融未查询到项目信息!");
            }
            BaseLogUtils.newWebLogger("三一金融自然人查询客户信息Start:cstId:" + cstId).info();
            CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectBy(cstId, prjBscInfoVO.getBuOrgCd());
            BaseLogUtils.newWebLogger("三一金融自然人查询客户信息End:cstId:" + cstId + ",cstBscInfoVO:" + JSON.toJSONString(cstBscInfoVO)).info();
            if (null == cstBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融自然人未查询到客户信息!");
            }

            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SYFL);
            BaseLogUtils.newWebLogger("三一金融自然人获取账户信息,prjId:" + prjId).info();
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            BaseLogUtils.newWebLogger("三一金融自然人获取账户信息,prjId:" + prjId  + ",prjCstAccInfoVOS:" + JSON.toJSONString(prjCstAccInfoVOS)).info();
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("请先保存项目客户信息");
                return dataResultVO;
            }
            // 四要素验证
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);

            if (null == prjCstAccInfoVO.getAccResCd() || InsAccResEnum.INIT_STATUS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("请先保存项目客户信息");
                return dataResultVO;
            } else if (InsAccResEnum.SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd()) || InsAccResEnum.SEC_BIND_SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("已绑卡,无需再次获取");
                return dataResultVO;
            }
            // 发送短信
            DataResultDTO dto = this.syflInsApiService.getVerificationCodeForNp(String.valueOf(prjId));
            if (null == dto) {
                dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "调用获取验证码接口返回空");
            } else {
                if (dto.getCode().equals(BaseConstant.IS_YESNO_YES_NM)) {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                }
                if (dto.getCode().equals(BaseConstant.IS_YESNO_NO_NE)) {
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                }
                dataResultVO.setInfo(dto.getInfo());
                dataResultVO.setData(dto.getData());
            }
        } catch (Exception e) {
            BaseLogUtils.newWebLogger("三一金融自然人调用获取验证码接口异常,prjId:" + prjId + ",e:" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_NO, "调用获取验证码接口异常,"+e);
        }
        BaseLogUtils.newWebLogger("三一金融自然人获取验证码结果,prjId:" + prjId + ",dataResultVO:" + JSON.toJSONString(dataResultVO)).info();
        return dataResultVO;
    }

    @RequestMapping(value = "/syflBindCardForNp.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object syflBindCardForNp(Long prjId, PrjCstAccInfoQueryCondition prjCstAccInfoQC, HttpServletRequest request) throws BaseException {
        BaseLogUtils.newWebLogger("三一金融自然人绑卡:prjId:" + prjId + ",prjCstAccInfoQC:" + JSON.toJSONString(prjCstAccInfoQC)).info();
        Long startTm = System.currentTimeMillis();
        DataResultVO dataResultVO = new DataResultVO(BaseConstant.IS_YESNO_YES, "自然人绑卡成功");
        String vCode = prjCstAccInfoQC.getPhoneCode();
        if (StringUtils.isEmpty(prjId)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "项目id为空!");
        }
        if (StringUtils.isBlank(vCode)) {
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "请输入验证码!");
        }
        try {
            BaseLogUtils.newWebLogger("三一金融自然人查询项目信息Start:prjId:" + prjId).info();
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjId);
            BaseLogUtils.newWebLogger("三一金融自然人查询项目信息End:prjId:" + prjId + ",prjBscInfoVO:" + prjBscInfoVO).info();
            if (null == prjBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融未查询到项目信息!");
            }
            BaseLogUtils.newWebLogger("三一金融自然人查询客户信息Start:cstId:" + prjBscInfoVO.getCstId()).info();
            CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectBy(prjBscInfoVO.getCstId(), prjBscInfoVO.getBuOrgCd());
            BaseLogUtils.newWebLogger("三一金融自然人查询客户信息End:cstId:" + prjBscInfoVO.getCstId() + ",cstBscInfoDTO:" + JSON.toJSONString(cstBscInfoVO)).info();
            if (null == cstBscInfoVO) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "三一金融自然人未查询到客户信息!");
            }

            PrjCstAccInfoQueryCondition prjCstAccInfoQueryCondition = new PrjCstAccInfoQueryCondition();
            prjCstAccInfoQueryCondition.setPrjId(prjId);
            prjCstAccInfoQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
            prjCstAccInfoQueryCondition.setInsCode(PrjBscInfoConstant.PRJ_INS_CODE_SYFL);
            BaseLogUtils.newWebLogger("三一金融自然人查询客户账户信息Start:prjId:" + prjId).info();
            List<PrjCstAccInfoVO> prjCstAccInfoVOS = this.prjCstAccInfoService.searchList(prjCstAccInfoQueryCondition);
            BaseLogUtils.newWebLogger("三一金融自然人查询客户账户信息End:prjId:" + prjId + ",prjCstAccInfoVOS:" + JSON.toJSONString(prjCstAccInfoVOS)).info();
            if(CollectionUtils.isEmpty(prjCstAccInfoVOS)){
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请先保存项目客户信息");
            }
            PrjCstAccInfoVO prjCstAccInfoVO = prjCstAccInfoVOS.get(0);

            if (null == prjCstAccInfoVO.getAccResCd() || InsAccResEnum.INIT_STATUS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请先保存项目客户信息");
            } else if (InsAccResEnum.SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd()) || InsAccResEnum.SEC_BIND_SUCCESS.code.equals(prjCstAccInfoVO.getAccResCd())) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "已绑卡,无需再次绑卡");
            }

            // 签约绑卡
            BaseLogUtils.newWebLogger("三一金融自然人绑卡Start:prjId:" + prjId + ",vCode:" + vCode).info();
            DataResultDTO dataResultDTO = this.syflInsApiService.signForNp(String.valueOf(prjId), vCode);
            BaseLogUtils.newWebLogger("三一金融自然人绑卡End:prjId:" + prjId + ",vCode:" + vCode + ",dataResultDTO:" + JSON.toJSONString(dataResultDTO)).info();
            if(dataResultDTO!=null){
                if(BaseConstant.IS_YESNO_YES_NM.equals(dataResultDTO.getCode())) {//签约绑卡成功
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_YES);
                    dataResultVO.setInfo(dataResultDTO.getInfo());
                }else{//签约绑卡失败
                    dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                    dataResultVO.setInfo(dataResultDTO.getInfo());
                }
                dataResultVO.setData(dataResultDTO.getData());
            }else{//签约绑卡失败
                dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
                dataResultVO.setInfo("很抱歉,您本次的绑卡操作失败,请重新操作绑卡");
            }
        } catch (BaseException ex) {
            dataResultVO.setSuccess(BaseConstant.IS_YESNO_NO);
            dataResultVO.setInfo(ex.getMessage());
            BaseLogUtils.newWebLogger("三一金融自然人绑卡失败:prjId:" + prjId + ",vCode:" + vCode + ",ex:" + ex.getMessage()).info();
        } catch (Exception e){
            BaseLogUtils.newWebLogger("三一金融自然人绑卡失败,系统异常:prjId:" + prjId + ",vCode:" + vCode + ",e:" + e.getMessage()).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
            return new DataResultVO(BaseConstant.IS_YESNO_NO, "很抱歉,您本次的绑卡操作失败,请重新操作绑卡");
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.newWebLogger("三一金融法人自然人返回:prjId:" + prjId + ",vCode:" + vCode + ",dataResultVO:" + JSON.toJSONString(dataResultVO) + "-耗时:" + (endTm - startTm)).info();
        return dataResultVO;
    }
}
